import type { Router } from 'vue-router';

import { setRouteEmitter, setRouteFromEmitter } from '@/utils/route-listener';

import setupPermissionGuard from './permission';
import setupUserLoginInfoGuard from './userLoginInfo';

function setupPageGuard(router: Router) {
  router.beforeEach(async (to, from) => {
    setRouteEmitter(to);
    setRouteFromEmitter(from);
  });
}

export default function createRouteGuard(router: Router) {
  setupPageGuard(router);
  setupUserLoginInfoGuard(router);
  setupPermissionGuard(router);
}
